package com.xqy.thread;

import java.util.concurrent.*;

public class TestCallable implements Callable<String> {
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName());
        return Thread.currentThread().getName();
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        TestCallable t1 = new TestCallable();
        TestCallable t2 = new TestCallable();
        TestCallable t3 = new TestCallable();
        //创建执行服务
        ExecutorService service = Executors.newFixedThreadPool(3);

        //提交执行
        final Future<String> f1  = service.submit(t1);
        final Future<String> f2  = service.submit(t2);
        final Future<String> f3  = service.submit(t3);
        //获取结果
        String r1 = f1.get();
        String r2 = f2.get();
        String r3 = f3.get();
        System.out.println(service);
        //关闭服务
        System.out.println(r1);
        System.out.println(r2);
        System.out.println(r3);

        service.shutdownNow();
    }
}
